package com.ysynzehao.dao;

import com.ysynzehao.bean.User;
import com.ysynzehao.dao.utils.BaseRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Map;

/**
 * niuzehao
 * 2018/12/3 16:20.
 */
public interface UserRepository extends BaseRepository<User, Integer> {

    List<User> findByAgeIsLessThanAndUserNameLike(int age, String userName);

    @Query(value = "select * from user where user_name=?1 and age = ?2", nativeQuery = true)
    List<User> findByUserNameAndAgeSql(String userName, int age);

    @Query("select user from User as user where userName=:userName")
    List<User> findByUserNameHql(@Param("userName") String userName);

    @Query("select new map(u.userId as userId, u.userName as userName) from User u")
    List<Map<Integer, String>> findUserIdNameMap();
}
